﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WaiShop.Core
{
    public static class ConfigurationHelper
    {
        /// <summary>
        /// 根据Key得到对应的值
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public static string GetAppSettingeValue(string key)
        {
            var result = ConfigurationManager.AppSettings[key];
            return result == null ? "" : result;
        }

        /// <summary>
        /// 根据Section得到Key得到对应的值
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public static string GetSectionValue(string section,string key)
        {
            IDictionary dic =(IDictionary) ConfigurationManager.GetSection(section);
            var result = dic[key];
            return result == null ? "" : result.ToString();
        }


        /// <summary>
        /// 根据Section得到Key
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public static List<string> GetKeys(string section)
        {
            List<string> keyList = new List<string>();
            IDictionary dic = (IDictionary)ConfigurationManager.GetSection(section);
            foreach (var item in dic.Keys)
            {
                keyList.Add(item.ToString());
            }
            return keyList;
        }
    }
}
